package com.example.cofeed.activity;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.cofeed.R;
import com.example.cofeed.adapter.AttentionAdapter;
import com.example.cofeed.adapter.PushSubscriptionAdapter;
import com.example.cofeed.api.ApiService;
import com.example.cofeed.base.BaseActivity;
import com.example.cofeed.base.BaseListActivity;
import com.example.cofeed.callback.DialogCallback;
import com.example.cofeed.callback.LzyResponse;
import com.example.cofeed.entity.Attention;
import com.example.cofeed.entity.Catalogs;
import com.lzy.okgo.model.Response;
import com.umeng.analytics.MobclickAgent;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import java.util.List;

public class MyAttentionActivity extends BaseListActivity<Attention> {
    private AttentionAdapter pushSubscriptionAdapter;

    @Override
    protected void bindRecyclerView(RecyclerView recLv) {
        setMainTitle("我的关注");
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recLv.setLayoutManager(linearLayoutManager);
        pushSubscriptionAdapter = new AttentionAdapter();
        recLv.setAdapter(pushSubscriptionAdapter);
        recLv.addItemDecoration(
                new HorizontalDividerItemDecoration.Builder(this)
                        .color(Color.TRANSPARENT)
                        .sizeResId(R.dimen.dp_10)
                        .build());

        pushSubscriptionAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Attention pushSubscription = (Attention) adapter.getData().get(position);
                pushSubscriptionAdapter.setSelect(pushSubscription);

            }
        });

        refreshLayout.setEnableLoadMore(false);

    }

    @Override
    protected void loadData(int page, int pageCount) {
        ApiService.get_followinfo(this, new DialogCallback<LzyResponse<List<Attention>>>() {
            @Override
            public void onSuccess(Response<LzyResponse<List<Attention>>> response) {
                for (Attention catalogs:response.body().data) {
                    catalogs.isSelect = true;
                }
                onGetDataSuc(response.body().data);
            }

            @Override
            public void onError(Response<LzyResponse<List<Attention>>> response) {
                super.onError(response);
                onGetDataFail();
            }
        });

    }

    @Override
    protected List<Attention> getData() {
        return pushSubscriptionAdapter.getData();
    }

    @Override
    protected void bindData(boolean isRefresh, List<Attention> list) {
        if (isRefresh){
            pushSubscriptionAdapter.setNewData(list);
        }else {
            pushSubscriptionAdapter.addData(list);
        }
    }

//    @Override
//    protected int getLayoutId() {
//        return R.layout.activity_my_attention;
//    }
//
//    @Override
//    protected void init(Bundle savedInstanceState, View container) {
//        setMainTitle("我的关注");
//
//    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

}
